#include "DebugCamera.h"

using namespace DirectX;
DebugCamera::DebugCamera(void)
{
	m_positionX = 0.0f;
	m_positionY = 0.0f;
	m_positionZ = 0.0f;

	m_rotationX = 0.0f;
	m_rotationY = 0.0f;
	m_rotationZ = 0.0f;

	m_position = m_rotation = XMVectorZero();
}


DebugCamera::~DebugCamera(void)
{
}


void DebugCamera::Initialize(XMVECTOR position, XMVECTOR rotation)
{
	m_position = position;
	m_rotation = rotation;
}
void DebugCamera::SetPosition(float x, float y, float z)
{
	m_positionX = x;
	m_positionY = y;
	m_positionZ = z;

	/*XMVectorSetX(m_position, x);
	XMVectorSetY(m_position, y);
	XMVectorSetZ(m_position, z);*/
	m_position = XMVectorSet(x,y,z,1);
	
	return;
}


void DebugCamera::SetRotation(float x, float y, float z)
{
	m_rotationX = x;
	m_rotationY = y;
	m_rotationZ = z;

	/*XMVectorSetX(m_rotation, x);
	XMVectorSetY(m_rotation, y);
	XMVectorSetZ(m_rotation, z);*/
	m_rotation = XMVectorSet(x,y,z,1);
	XMVECTOR hej;
	return;
}

void DebugCamera::Update(GameTime gameTime)
{
	XMVECTOR up = XMVectorZero();
	XMVECTOR lookAt = XMVectorZero();	
	
	float yaw, pitch, roll;
	XMMATRIX rotationMatrix;

	// Setup the vector that points upwards.
	up = XMVectorSetX(up, 0.0f);
	up = XMVectorSetY(up, 1.0f);
	up = XMVectorSetZ(up, 0.0f);


		// Setup where the camera is looking by default.
	lookAt = XMVectorSetX(lookAt, 0.0f);
	lookAt = XMVectorSetY(lookAt, 0.0f);
	lookAt = XMVectorSetZ(lookAt, 1.0f);

	// Set the yaw (Y axis), pitch (X axis), and roll (Z axis) rotations in radians.
	pitch = m_rotationX * 0.0174532925f;
	yaw   = m_rotationY * 0.0174532925f;
	roll  = m_rotationZ * 0.0174532925f;

	// Create the rotation matrix from the yaw, pitch, and roll values.
	rotationMatrix = XMMatrixRotationRollPitchYaw(pitch,yaw,roll);
	

	// Transform the lookAt and up vector by the rotation matrix so the view is correctly rotated at the origin.
	lookAt = XMVector3TransformCoord(lookAt, rotationMatrix);
	up = XMVector3TransformCoord(up, rotationMatrix);
	//D3DXVec3TransformCoord(&lookAt, &lookAt, &rotationMatrix);
	//D3DXVec3TransformCoord(&up, &up, &rotationMatrix);

	// Translate the rotated camera position to the location of the viewer.
	lookAt = m_position + lookAt;

	// Finally create the view matrix from the three updated vectors.
	m_viewMatrix = XMMatrixLookAtLH( m_position, lookAt,up);

	return;
}

void DebugCamera::GetViewMatrix(DirectX::XMMATRIX& view)
{
	view = m_viewMatrix;
	return;
}

void DebugCamera::GetProjectionMatrix(DirectX::XMMATRIX& projection)
{
	projection = m_projectionMatrix;
	return;
}


XMVECTOR DebugCamera::GetPosition()
{
	return m_position;
}


XMVECTOR DebugCamera::GetRotation()
{
	return m_rotation;
}